package com.javacv.plus.extensions.image.config;

import com.javacv.plus.core.config.ProcessorConfig;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 图像处理配置
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ImageConfig extends ProcessorConfig {

    /**
     * 默认输出格式
     */
    private String outputFormat = "jpg";

    /**
     * 图像质量 (0-100)
     */
    private int quality = 90;

    /**
     * 是否保持宽高比
     */
    private boolean keepAspectRatio = true;

    /**
     * 默认背景色 (RGB)
     */
    private int[] backgroundColor = {255, 255, 255};

    /**
     * 水印透明度 (0.0-1.0)
     */
    private double watermarkOpacity = 0.7;

    /**
     * 水印位置
     */
    private WatermarkPosition watermarkPosition = WatermarkPosition.BOTTOM_RIGHT;

    /**
     * 水印边距
     */
    private int watermarkMargin = 10;

    /**
     * 文字字体大小
     */
    private int fontSize = 24;

    /**
     * 文字颜色 (RGB)
     */
    private int[] textColor = {0, 0, 0};

    /**
     * 水印位置枚举
     */
    public enum WatermarkPosition {
        TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER
    }

    /**
     * 创建图像配置构建器
     */
    public static ImageConfigBuilder imageBuilder() {
        return new ImageConfigBuilder();
    }

    /**
     * 图像配置构建器
     */
    public static class ImageConfigBuilder {
        private ImageConfig config = new ImageConfig();

        public ImageConfigBuilder outputFormat(String format) {
            config.setOutputFormat(format);
            return this;
        }

        public ImageConfigBuilder quality(int quality) {
            if (quality < 0 || quality > 100) {
                throw new IllegalArgumentException("质量值必须在0-100之间");
            }
            config.setQuality(quality);
            return this;
        }

        public ImageConfigBuilder keepAspectRatio(boolean keep) {
            config.setKeepAspectRatio(keep);
            return this;
        }

        public ImageConfigBuilder backgroundColor(int r, int g, int b) {
            config.setBackgroundColor(new int[]{r, g, b});
            return this;
        }

        public ImageConfigBuilder watermarkOpacity(double opacity) {
            if (opacity < 0.0 || opacity > 1.0) {
                throw new IllegalArgumentException("透明度必须在0.0-1.0之间");
            }
            config.setWatermarkOpacity(opacity);
            return this;
        }

        public ImageConfigBuilder watermarkPosition(WatermarkPosition position) {
            config.setWatermarkPosition(position);
            return this;
        }

        public ImageConfigBuilder watermarkMargin(int margin) {
            config.setWatermarkMargin(margin);
            return this;
        }

        public ImageConfigBuilder fontSize(int size) {
            config.setFontSize(size);
            return this;
        }

        public ImageConfigBuilder textColor(int r, int g, int b) {
            config.setTextColor(new int[]{r, g, b});
            return this;
        }

        public ImageConfig build() {
            return config;
        }
    }
} 